package com.haople.test.trace;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.ParseException;

/**
 * Hello world!
 *
 */
public class StartUp 
{
    public static void main( String[] args )
    {
    	try {
    		String url=null;
    		Integer num=1;
    		if(args==null || args.length==0 ){
    			Cli.help();
    			return;
    		}
			CommandLineParser parser = new DefaultParser(); //默认的匹配器
			CommandLine cmd = parser.parse(Cli.getOptions(), args); // 定义和输入进行匹配
			if(cmd.hasOption('h')){
				Cli.help();
			}
			if(cmd.hasOption('n')){
				num=Integer.parseInt(cmd.getOptionValue('n', "1"));
			}
			if(num==null || num<=0){
				num=1;
			}
			if(cmd.hasOption('b')){
				url=cmd.getOptionValue('b');
				if(url==null || url.equals("")){
					System.out.println("please input url");
					return;
				}
				Cli.crawlByHttp(url, num);
			}
			if(cmd.hasOption('t')){
				url=cmd.getOptionValue('t');
				if(url==null || url.equals("")){
					System.out.println("please input url");
					return;
				}
				Cli.crawlByHttpUnit(url, num);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
    }
}
